// app.js

import {getOpenId} from "./api/api"

App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        getOpenId({jsCode:res.code}).then(res=>{
          let data = JSON.parse(res.msg);
          if(data.openid){
            this.globalData.openid = data.openid;
          }else{
            wx.showToast({
              title: '网络连接失败',
              icon:"none"
            })
          }
        });
        wx.getUserProfile({
          desc: '用于获取用户昵称、头像',
          success:(res)=>{
            console.log(res);
          },
        });
      }
    });
  },
  globalData: {
    userinfo: null,
    openid:null,
    questions:[]
  }
})
